//
//  NYTitleViewSearchBar.m
//  Nooryes
//
//  Created by baken on 2020/3/10.
//  Copyright © 2020 MyApp. All rights reserved.
//

#import "NYTitleViewSearchBar.h"


@interface NYTitleViewSearchBar()<UISearchBarDelegate>


@end

@implementation NYTitleViewSearchBar


-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self setupSearchBar];
    }
    return self;
}


-(void)setupSearchBar{
    
    //输入框
    _searchBar = [[UISearchBar alloc] initWithFrame:self.bounds];
    _searchBar.searchBarStyle = UISearchBarStyleMinimal;
    _searchBar.backgroundColor = UIColorFromRGB(0xf2f2f2);
    _searchBar.delegate = self;
    //键盘属性
    _searchBar.returnKeyType = UIReturnKeySearch;
//    _searchBar.layer.cornerRadius = 14;
//    _searchBar.layer.masksToBounds = YES;
    
    
 
    _searchBar.placeholder = @"搜索";
//    _searchBar setPositionAdjustment:<#(UIOffset)#> forSearchBarIcon:<#(UISearchBarIcon)#>
    
    
    [self addSubview:_searchBar];
}
- (CGSize)intrinsicContentSize{
    
    return UILayoutFittingExpandedSize;
    
}

-(BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{
//    NSString *text = searchBar.text;
//    if ([[text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:@""]) {
//        return NO;
//    }
    return YES;
}

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    _searchBlock(searchBar.text);
}

@end
